// 地址
const HOST = "https://apis.netstart.cn/yunyuedu/";

const http = (url = '', data = {}, method = 'GET') => {
  return new Promise((resolve, reject) => {
    wx.showLoading({
      title: '正在加载...',
    })
    wx.request({
      url: HOST + url,
      data,
      method,
      success: function (result) {
        wx.hideLoading();
        // 获取成功，前置拦截器
        if (result.data) {
          if (result.data.data) {
            resolve(result.data.data);
            return;
          }
          resolve(result.data);
          return;
        }
        resolve(result);
      },
      fail:function(error){
        reject(error)
      }
    })
  })
}
const get =(url="",data={})=>{
  return http(url,data,"GET")
};
const post = (url="",data={})=>{
  return http(url,data,"POST")
};
module.exports = {
  http,
  get,
  post
}